﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace mvc3App.DataStore.Entities
{
    public class OccasionEntity : Microsoft.WindowsAzure.StorageClient.TableServiceEntity
    {
        public Guid UserID { get; set; }
        public Guid OccasionId { get; set; }
        public string Name { get; set; }
        public DateTime DateTime { get; set; }

        public OccasionEntity() { }
            
        public OccasionEntity(Occasion occasion)
        {
            UserID = occasion.UserID;
            OccasionId = occasion.OccasionID;
            Name = occasion.Name;
            DateTime = occasion.DateTime;
            PartitionKey = UserID.ToString();
            RowKey = OccasionId.ToString();
        }

        internal void Insert(string occasionTable, Microsoft.WindowsAzure.StorageClient.TableServiceContext serviceContext)
        {
            serviceContext.AddObject(occasionTable, this);
            serviceContext.SaveChangesWithRetries(System.Data.Services.Client.SaveChangesOptions.None);
        }
    }

    public class OneDrinkEntity : Microsoft.WindowsAzure.StorageClient.TableServiceEntity
    {
        public Guid OccasionID { get; set; }
        public string DrinkName { get; set; }
        public int Amount { get; set; }
        public DateTime Time { get; set; }
        //public int AlcoholPercent { get; set; }
        
        public OneDrinkEntity() { }

        public OneDrinkEntity(Guid occaionID, OneDrink oneDrink)
        {
            OccasionID = occaionID;
            DrinkName = oneDrink.Beverage.Name;
            Amount = oneDrink.Amount;
            Time = oneDrink.Time;
            //AlcoholPercent = oneDrink.Beverage.AlcoholPercent;
            PartitionKey = OccasionID.ToString();
            RowKey = DrinkName;
        }

        internal void Insert(string onedrinkTable, Microsoft.WindowsAzure.StorageClient.TableServiceContext serviceContext)
        {
            serviceContext.AddObject(onedrinkTable, this);
            serviceContext.SaveChangesWithRetries(System.Data.Services.Client.SaveChangesOptions.None);
        }
    }

    public class BeverageEntity : Microsoft.WindowsAzure.StorageClient.TableServiceEntity
    {
        public string Name { get; set; }
        public int AlcoholPercent { get; set; }

        public BeverageEntity() { }

        public BeverageEntity(OneDrink oneDrink)
        {
            Name = oneDrink.Beverage.Name;
            AlcoholPercent = oneDrink.Beverage.AlcoholPercent;
            PartitionKey = "";
            RowKey = oneDrink.Beverage.Name;
        }

        internal void Insert(string beverageTable, Microsoft.WindowsAzure.StorageClient.TableServiceContext serviceContext)
        {
            serviceContext.AddObject(beverageTable, this);
            serviceContext.SaveChangesWithRetries(System.Data.Services.Client.SaveChangesOptions.None);
        }
    }
}